package oj.oj_876;
import oj.ListNode;

/**
 * oj常见思路：双指针思路，块指针走两步，慢指针走一步
 */

public class Solution2 {//快快慢
        // 时间复杂度：O(n)
        // 空间复杂度：O(1)
        public ListNode middleNode(ListNode head) {
            if (head == null) {
                return null;
            }

            ListNode fast = head;
            ListNode slow = head;

            while (true) {
                fast = fast.next;
                if (fast == null) {
                    break;
                }
                slow = slow.next;
                fast = fast.next;
                if (fast == null) {
                    break;
                }
            }
            return slow;
        }
    }
